package com.gf.gf_data.sys.exception;

/**
 * Created by Eternal_L on 2017/12/21.
 */
public enum ExceptionEnum {

    /* -----------------------------统一异常捕获-------------------------------------*/
    /* 说明：以下的异常名称定义，为了可读性均是异常原名，不建议作全部大写'_'分隔样式
    /* ---------------------------------------------------------------------------*/

    /* ---------------------------基本本异常(10***)----------------------------------*/
    /** 空指针异常 */
    NullPointerException(10000,"null pointer exception"),
    /** IO异常 */
    IOException(10001,"IO exception"),
    /** 类型强制转换异常 */
    ClassCastException(10002,"class cast exception"),
    /** 算术异常 */
    ArithmeticException(10003,"arithmetic exception"),
    /** 数组下标越界 */
    IndexOutOfBoundsException(10004,"index out of bounds exception"),
    /** 数组存储异常 */
    ArrayStoreException(10005,"array store exception"),
    /** 方法末找到异常 */
    NoSuchMethodError(10006,"no such method error"),
    /** 数据库操作异常 */
    DataAccessException(10007, "data access exception"),
    /** 方法参数错误或非法 */
    IllegalArgumentException(10008,"illegal argument exception"),
    /** 违背安全原则异常 */
    SecurityException(10009,"security exception"),
    /** 没有权限 */
    UnauthorizedException(10010, "unauthorized exception"),


    HttpMessageNotReadableException(400, "Bad Request"),

//    TypeMismatchException(400, "Bad Request"),
//
//    MissingServletRequestParameterException(400, "Bad Request"),

    NoSuchRequestHandlingMethodException(404, "Not Found)"),

    HttpRequestMethodNotSupportedException(405, "Method Not Allowed"),

    HttpMediaTypeNotAcceptableException(406, "Not Acceptable"),

    HttpMediaTypeNotSupportedException(415, "Unsupported Media Type"),


    INTERNAL_SERVER_ERROR(500, "Internal Server Error");


    private int state;    // 状态码

    private String msg;   // 异常描述信息

    ExceptionEnum(int state, String msg) {
        this.state = state;
        this.msg = msg;
    }

    public int getState() {
        return state;
    }

    public String getMsg() {
        return msg;
    }

    public static ExceptionEnum stateOf(int index) {
        for (ExceptionEnum resultEnum : ExceptionEnum.values()) {
            if (resultEnum.getState() == index) {
                return resultEnum;
            }
        }
        return null;
    }

    public static String stateOfValue(int index) {
        for (ExceptionEnum resultEnum : ExceptionEnum.values()) {
            if (resultEnum.getState() == index) {
                return resultEnum.getMsg();
            }
        }
        return null;
    }

}
